package servlet;

import model.Type;
import service.TypeService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "AdminTypeListServlet", value = "/admin/type_list")
public class AdminTypeListServlet extends HttpServlet {
    private TypeService tService = new TypeService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<Type> list= tService.GetAllType();
        request.setAttribute("list", list);
        this.getServletContext().removeAttribute("typeList");
        this.getServletContext().setAttribute("typeList",list);
        request.getRequestDispatcher("/admin/type_list.jsp").forward(request, response);
    }
}
